package com.probox.modules.controller.order;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.order.OrderComplaint;
import com.probox.common.entity.service.order.IOrderComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 客户投诉Controller
 *
 * @author hds
 * @date 2021-06-07
 */
@RestController
@RequestMapping("/order/complaint")
public class OrderComplaintController extends BaseController {
    @Autowired
    private IOrderComplaintService orderComplaintService;

    /**
     * 查询客户投诉列表
     */
    @PreAuthorize(hasPermi = "order:complaint:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderComplaint orderComplaint) {
        startPage();
        List<OrderComplaint> list = orderComplaintService.queryList(orderComplaint);
        return getDataTable(list);
    }

    /**
     * 导出客户投诉列表
     */
    @PreAuthorize(hasPermi = "order:complaint:export")
    @Log(title = "客户投诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderComplaint orderComplaint) throws IOException {
        List<OrderComplaint> list = orderComplaintService.queryList(orderComplaint);
        ExcelUtil<OrderComplaint> util = new ExcelUtil<OrderComplaint>(OrderComplaint.class);
        util.exportExcel(response, list, "客户投诉数据");
    }

    /**
     * 获取客户投诉详细信息
     */
    @PreAuthorize(hasPermi = "order:complaint:query")
    @GetMapping(value = "/{complaintId}")
    public AjaxResult getInfo(@PathVariable("complaintId") Long complaintId) {
        return AjaxResult.success(orderComplaintService.selectOrderComplaintById(complaintId));
    }

    /**
     * 新增客户投诉
     */
    @PreAuthorize(hasPermi = "order:complaint:add")
    @Log(title = "客户投诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderComplaint orderComplaint) {
        return toAjax(orderComplaintService.insertOrderComplaint(orderComplaint));
    }

    /**
     * 修改客户投诉
     */
    @PreAuthorize(hasPermi = "order:complaint:edit")
    @Log(title = "客户投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderComplaint orderComplaint) {
        return toAjax(orderComplaintService.updateOrderComplaint(orderComplaint));
    }

    /**
     * 修改状态
     */
    @PreAuthorize(hasPermi = "order:complaint:edit")
    @Log(title = "客户投诉", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody OrderComplaint orderComplaint) {
        return toAjax(orderComplaintService.updateOrderComplaint(orderComplaint));
    }


    /**
     * 删除客户投诉
     */
    @PreAuthorize(hasPermi = "order:complaint:remove")
    @Log(title = "客户投诉", businessType = BusinessType.DELETE)
    @DeleteMapping("/{complaintIds}")
    public AjaxResult remove(@PathVariable Long[] complaintIds) {
        return toAjax(orderComplaintService.deleteOrderComplaintByIds(complaintIds));
    }
}
